import 'dart:async';

import 'package:flutter/material.dart';
import 'package:pabu/widget/main_page.dart';

class SplashPage extends StatefulWidget {
  @override
  _SplashPageState createState() => new _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {
  @override
  Widget build(BuildContext context) {
    return new Material(
      color: Colors.blue,
      child: Container(
        alignment: Alignment(0, -0.3),
        child: new Text(
          "Gnerv",
          style: new TextStyle(
            color: Colors.white,
            fontSize: 50.0,
            fontWeight: FontWeight.bold,
          ),
        ),
      ),
    );
  }

  Timer _timer;

  @override
  void initState() {
    super.initState();
    _timer = new Timer(const Duration(milliseconds: 500), () {
      Navigator.of(context).pushAndRemoveUntil(
          PageRouteBuilder<Null>(
            pageBuilder: (BuildContext buildContent,
                Animation<double> animation,
                Animation<double> secondaryAnimation) {
              return AnimatedBuilder(
                  animation: animation,
                  builder: (BuildContext buildContent, Widget child) {
                    return Opacity(
                      opacity: animation.value,
                      child: new MainPage(),
                    );
                  });
            },
            transitionDuration: Duration(milliseconds: 300),
          ),
          (Route route) => route == null);
    });
  }

  @override
  void dispose() {
    _timer.cancel();
    super.dispose();
  }
}
